<template>
    <div class="container">
        <div class="flex-container">
            <div class="flex-item">
                <div class="date-c">
                    <div class="date" @click="selectTime(0)">开始日期：{{startTime?$moment(startTime).
                        format('YYYY-MM-DD HH:mm'):"不限"}}
                    </div>
                    <div class="date" @click="selectTime(1)"
                         style="margin-top: 4px">截止日期： {{endTime?$moment(endTime).format('YYYY-MM-DD HH:mm'):"不限"}}
                    </div>
                    <div>
                        <el-button type="primary" size="small" @click="searchData(0)">确定</el-button>
                        <el-button type="default" size="small" @click="searchData(1)">重置</el-button>
                    </div>
                </div>
            </div>
        </div>
        <el-tabs v-model="activeName">
            <el-tab-pane label="现有库存" name="have">
                <el-table :data="kucunData.have" class="el-mb-15" stripe>
                    <el-table-column prop="id" label="id"/>
                    <el-table-column prop="name" label="名称"/>
                    <el-table-column fixed="right" label="数量">
                        <template slot-scope="scope">
                            {{scope.row.sumNumber}}
                            {{scope.row.danweiming}}
                        </template>
                    </el-table-column>
                </el-table>
            </el-tab-pane>
            <el-tab-pane label="入库库存" name="in">
                <el-table :data="kucunData.in" class="el-mb-15" stripe>
                    <el-table-column prop="id" label="id"/>
                    <el-table-column prop="name" label="名称"/>
                    <el-table-column fixed="right" label="数量">
                        <template slot-scope="scope">
                            {{scope.row.sumNumber}}
                            {{scope.row.danweiming}}
                        </template>
                    </el-table-column>
                </el-table>
            </el-tab-pane>
            <el-tab-pane label="出库库存" name="out">
                <el-table :data="kucunData.out" class="el-mb-15" stripe>
                    <el-table-column prop="id" label="id"/>
                    <el-table-column prop="name" label="名称"/>
                    <el-table-column fixed="right" label="数量">
                        <template slot-scope="scope">
                            {{scope.row.sumNumber}}
                            {{scope.row.danweiming}}
                        </template>
                    </el-table-column>
                </el-table>
            </el-tab-pane>
        </el-tabs>
        <van-popup v-model="timeSection.show" position="bottom" :close-on-click-overlay="false">
            <div v-show="curTime==0">
                <van-datetime-picker v-model="curTimeValue" @cancel="timeSection.show = false"
                                     @confirm="startTimeSection" type="datetime"/>
            </div>
            <div v-show="curTime==1">
                <van-datetime-picker v-model="curTimeValue" @cancel="timeSection.show = false"
                                     @confirm="endTimeSection" type="datetime"/>
            </div>
        </van-popup>
    </div>
</template>

<script>

    import fly from "../../../src/libs/js/request.js"
    import {DatetimePicker, Popup} from 'vant';

    export default {
        name: 'salesmanIndexs',
        components: {
            [DatetimePicker.name]: DatetimePicker, [Popup.name]: Popup,

        },
        data() {
            return {
                activeName: "have",
                timeSection: {
                    show: false,
                },
                curTime: 0,
                curTimeValue: "",
                startTime: "",
                endTime: "",
                kucunData: {}

            }
        },
        mounted() {
            this.onLoadMenDian();
        },
        methods: {
            selectTime(index) {
                this.curTime = index;
                this.timeSection.show = true
            },
            startTimeSection(data) {
                console.log('data ', data)
                this.startTime = data.getTime();
                this.timeSection.show = false
            },
            endTimeSection(data) {
                this.endTime = data.getTime();
                this.timeSection.show = false
            },
            searchData(index) {
                if (index == 1) {
                    this.startTime = "";
                    this.endTime = "";
                }

                this.onLoadMenDian()
            },


            async onLoadMenDian() {
                let params = {};
                params.token = this.$store.state.options.user.token;
                params.startTime = this.startTime ? parseInt(this.startTime / 1000) : "";
                params.endTime = this.endTime ? parseInt(this.endTime / 1000) : "";
                let res = await fly.post("/api/home/order/getStockReport", params);
                if (res.code == 200) {
                    this.kucunData = res.data;
                }
            },


        }
    }
</script>

<style lang="scss" scoped>
    .date-c {
        padding: 10px;
        font-size: 14px;
        height: 80px;
        border-bottom: 3px solid #EEEEEE;
        background-color: white;
        display: flex;
        align-items: center;

        .date {
            padding: 8px 20px;
            border: 1px solid #dddfe2;
            width: 200px;
            border-radius: 5px;
            display: inline-block;
            margin-right: 10px;
        }
    }

    .searchBtn {
        display: inline-block;
        padding: 5px 15px;
        font-size: 12px;
        text-align: center;
        color: white;
        background-color: #00CC00;
        margin-top: 5px;
        margin-right: 10px;
    }

    .bac-grey {
        background-color: #A3A3A3 !important;
    }

    .title {
        padding: 10px 10px;
        background-color: #EEEEEE;
    }

    .list {
        padding: 10px;
        font-size: 14px;
        border-bottom: 1px solid #EEEEEE;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .page-top {
        width: 100%;
        height: 3rem;
        position: relative;

        .notice {
            position: absolute;
            top: 0rem;
            width: 100%;
            margin: 0rem;
            padding: 0.7rem 1rem;
            display: flex;
            background: rgba(255, 247, 209, 1);
            z-index: 1;
            box-sizing: border-box;

            dt {
                padding-right: 1rem;

                img {
                    width: 1.4rem;
                }
            }

            dd {
                white-space: nowrap;
                flex: 1;
                margin: 0rem;
                padding: 0rem;
                color: #ff9000;
                font-size: 1.3rem;
            }
        }
    }

    .order-list-items {
        position: relative;
        margin-bottom: 4rem;

        .el-item {
            padding: 0.5rem 1rem;
        }
    }

    .order-list-contianer {
        border-bottom: 0.4rem solid #f4f4f4;

        ul {
            display: flex;
            border-bottom: 0.1rem solid #00cc00;

            li {
                padding: 1rem 0rem;
            }
        }

        ul li {
            flex: 1;
            display: flex;
            justify-content: center;
            align-items: center;

            color: #999999;
            font-size: 1.7rem;
        }

        .active {
            background-color: #00cc00;
            color: #ffffff;
            font-weight: 540;
        }
    }
</style>
